package myapps.ttclient.connection;

import android.content.SharedPreferences;

public class ConnectionListManager {

	private ConnectionList_Wifi connectionList_Wifi;
	private ConnectionList_Bluetooth connectionList_Bluetooth;

	public ConnectionListManager(SharedPreferences preferences) {
		connectionList_Wifi = new ConnectionList_Wifi(preferences);
		connectionList_Bluetooth = new ConnectionList_Bluetooth(preferences);

		this.Load();
	}

	public void Load() {
		//		{
		//			Connection_Wifi c = new Connection_Wifi();
		//			c.setHost("192.168.1.101");
		//			c.setName("AAaaBBbb");
		//			c.setPort(44472);
		//	
		//			connectionList_Wifi.add(c);
		//		}
		//		
		//		{
		//			Connection_Bluetooth c = new Connection_Bluetooth();
		//			c.setName("aaMMnnOO");
		//			
		//			connectionList_Bluetooth.add(c);
		//		}

		connectionList_Wifi.load();
		connectionList_Bluetooth.load();
		
		//useWifiConnectionList(2);

	}

	public void Save() {
		connectionList_Wifi.save();
		connectionList_Bluetooth.save();
	}

	public void useWifiConnectionList(int position) {
		connectionList_Wifi.setUsedPosition(position);
		connectionList_Bluetooth.setUsedPosition(-1);
	}

	public void useBluetoothConnectionList(int position) {
		connectionList_Bluetooth.setUsedPosition(position);
		connectionList_Wifi.setUsedPosition(-1);
	}

	public Connection getUsed() {
		Connection c = connectionList_Wifi.getUsed();

		if(c != null) {
			return c;
		}

		c = connectionList_Bluetooth.getUsed();

		if(c != null) {
			return c;
		}

		return 	null;
	}
	
	public void RemoveAll() {
		connectionList_Wifi.RemoveAll();
		connectionList_Bluetooth.RemoveAll();
	}

	public ConnectionList_Wifi getConnectionList_Wifi() {
		return connectionList_Wifi;
	}

	public void setConnectionList_Wifi(ConnectionList_Wifi connectionListWifi) {
		connectionList_Wifi = connectionListWifi;
	}

	public ConnectionList_Bluetooth getConnectionList_Bluetooth() {
		return connectionList_Bluetooth;
	}

	public void setConnectionList_Bluetooth(
			ConnectionList_Bluetooth connectionListBluetooth) {
		connectionList_Bluetooth = connectionListBluetooth;
	}
}